package com.zhan.ielts.dao.impl;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import com.zhan.frame.core.dao.impl.BaseDaoImpl;
import com.zhan.frame.core.exception.DaoException;
import com.zhan.ielts.dao.CompositionCorrectionDao;
import com.zhan.ielts.domain.CompositionCorrection;

@Repository
public class CompositionCorrectionDaoImpl extends
		BaseDaoImpl<CompositionCorrection> implements CompositionCorrectionDao {

	@Override
	public Long selectCurdateCount() {
		try {
			return sqlSessionTemplate.selectOne(getSqlName("selectCurdateCount"));
		} catch (Exception e) {
			throw new DaoException(String.format("查询对象总数出错！语句：%s", getSqlName("selectCurdateCount")), e);
		}
	}

	@Override
	public <CompositionCorrectionVo extends CompositionCorrection> Page<CompositionCorrectionVo> selectForTeacher(CompositionCorrection query, Pageable pageable) {
		try {
			List<CompositionCorrectionVo> contentList = sqlSessionTemplate.selectList(getSqlName("selectForTeacher"),
					getParams(query, pageable));
			return new PageImpl<CompositionCorrectionVo>(contentList, pageable, this.selectCount(query));
		} catch (Exception e) {
			throw new DaoException(String.format("根据分页对象查询列表出错！语句:%s", getSqlName("selectForTeacher")), e);
		}
	}
}
